package com.lnking.lnkingplace.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lnking.lnkingplace.mapper.InspectGroupMapper;
import com.lnking.lnkingplace.model.entity.InspectGroup;
import com.lnking.lnkingplace.model.request.inspect.inspectGroup.InspectGroupUpdateRequest;
import com.lnking.lnkingplace.service.IInspectGroupService;
import com.lnking.starter.mybatis.service.impl.CustomServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sn
 * @since 2022-09-21
 */
@Service
public class InspectGroupServiceImpl extends CustomServiceImpl<InspectGroupMapper, InspectGroup> implements IInspectGroupService {

    @Override
    public void insertByName(String group, String id) {
        InspectGroup inspectGroup = new InspectGroup();
        inspectGroup.setInspectId(id);
        inspectGroup.setGroupName(group);
        InspectGroup inspectGroupIsParent = selectByName(group, id);
        Assert.isNull(inspectGroupIsParent,"该组名已存在");
        getBaseMapper().insert(inspectGroup);
    }

    @Override
    public InspectGroup selectByName(String group, String id) {
        QueryWrapper<InspectGroup> Wapper =new QueryWrapper<>();
        Wapper.lambda().eq(InspectGroup::getInspectId,id);
        Wapper.lambda().eq(InspectGroup::getGroupName,group);
        InspectGroup inspectGroup = getBaseMapper().selectOne(Wapper);
        return inspectGroup;
    }

    @Override
    public void UpdateUserIds(InspectGroupUpdateRequest params) {
        InspectGroup inspectGroup = getBaseMapper().selectById(params.getInspectGroupId());
        inspectGroup.setUserIds(params.getUserIds());
        getBaseMapper().updateById(inspectGroup);

    }
}
